package com.sec.android.app.calculator;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.text.style.ScaleXSpan;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;

public class EventHandler
{
  private String[] checkChar;
  public boolean delst = false;
  public int errorCursor = 0;
  private SyntaxException exception = new SyntaxException();
  private String frontText = "";
  public Handler handler;
  private boolean isLongClick = false;
  private boolean isSelecting = false;
  private Context mContext;
  private boolean mCursorState = false;
  private EditText mDisplay;
  public boolean mEnterEnd = false;
  private History mHistory;
  private EditText mHistoryScreen;
  private boolean mIsError = false;
  public boolean mPaste = false;
  private Typeface mType;
  private StringBuilder sb;

  EventHandler(Context paramContext, EditText paramEditText1, EditText paramEditText2, History paramHistory)
  {
    String[] arrayOfString = new String[8];
    arrayOfString[0] = "sin(";
    arrayOfString[1] = "cos(";
    arrayOfString[2] = "tan(";
    arrayOfString[3] = "ln(";
    arrayOfString[4] = "abs(";
    arrayOfString[5] = "log(";
    arrayOfString[6] = "^(";
    arrayOfString[7] = "√(";
    this.checkChar = arrayOfString;
    this.handler = new Handler()
    {
      public void handleMessage(Message paramMessage)
      {
        if ((paramMessage.what != 0) || (!EventHandler.this.delst));
        while (true)
        {
          return;
          EventHandler.this.onBackspace();
          EventHandler.this.handler.sendEmptyMessage(0);
        }
      }
    };
    this.sb = new StringBuilder();
    this.mContext = paramContext;
    this.mDisplay = paramEditText1;
    this.mHistoryScreen = paramEditText2;
    this.mHistory = paramHistory;
    this.mType = Typeface.createFromAsset(this.mContext.getAssets(), "fonts/GS45_EU_TouchWiz.ttf");
  }

  public static int checkCharCount(StringBuilder paramStringBuilder, String paramString)
  {
    int i = 0;
    int j = 0;
    if (paramStringBuilder.length() == 0);
    for (int m = 0; ; m = i)
    {
      return m;
      while (true)
      {
        int k = paramStringBuilder.indexOf(paramString, j);
        if (k <= 0)
          break;
        i++;
        j = k + paramString.length();
      }
    }
  }

  private void clearSB()
  {
    int i = this.sb.length();
    if (i == 0);
    while (true)
    {
      return;
      this.sb.delete(0, i);
    }
  }

  public static String doubleToString(double paramDouble)
  {
    String str = Double.toString(Math.abs(paramDouble));
    StringBuffer localStringBuffer = new StringBuffer(str);
    int i = str.lastIndexOf('E');
    if (i != -1);
    int k;
    int m;
    for (int j = Integer.parseInt(str.substring(i + 1)); ; j = 0)
    {
      if (i != -1)
        localStringBuffer.setLength(i);
      k = localStringBuffer.length();
      for (m = 0; (m < k) && (localStringBuffer.charAt(m) != '.'); m++);
    }
    int n = j + m;
    if (m < k)
    {
      localStringBuffer.deleteCharAt(m);
      k--;
    }
    int i1;
    if (((n < 16) && (k >= 17)) || (n < -9))
      i1 = k - 1;
    int i2;
    int i11;
    while (true)
    {
      if (i1 >= k)
        break label576;
      if (localStringBuffer.charAt(i1) >= '5')
      {
        int i12 = i1 - 1;
        while (true)
          if ((i12 >= 0) && (localStringBuffer.charAt(i12) == '9'))
          {
            localStringBuffer.setCharAt(i12, '0');
            i12--;
            continue;
            i1 = 10 + n;
            break;
          }
        if (i12 < 0)
          break;
        localStringBuffer.setCharAt(i12, '\001' + localStringBuffer.charAt(i12));
        i2 = n;
        i11 = i1;
        localStringBuffer.setLength(i11);
      }
    }
    while (true)
    {
      int i3;
      if ((i2 < -5) || (i2 > 15))
      {
        if (localStringBuffer.length() <= 0)
          break label558;
        localStringBuffer.insert(1, '.');
        i3 = i2 - 1;
      }
      while (true)
      {
        label280: int i4 = localStringBuffer.length();
        int i5 = 0;
        while (true)
          if ((i5 < i4) && (localStringBuffer.charAt(i5) != '.'))
          {
            i5++;
            continue;
            localStringBuffer.insert(0, '1');
            int i13 = i1 + 1;
            i2 = n + 1;
            i11 = i13;
            break;
            for (int i9 = k; i9 < i2; i9++)
              localStringBuffer.append('0');
            for (int i10 = i2; i10 <= 0; i10++)
              localStringBuffer.insert(0, '0');
            if (i2 <= 0)
              i2 = 1;
            localStringBuffer.insert(i2, '.');
            i3 = 0;
            break label280;
          }
        int i6 = i4 - i5 - 1;
        if (i6 > 10)
        {
          i6 -= 10;
          for (int i8 = 0; i8 < i6; i8++)
            localStringBuffer.setCharAt(1 + (i8 + (i5 + 10)), '0');
        }
        for (int i7 = i4 - 1; (i7 >= 0) && (localStringBuffer.charAt(i7) == '0'); i7--)
          localStringBuffer.deleteCharAt(i7);
        if ((i7 >= 0) && (localStringBuffer.charAt(i7) == '.'))
          localStringBuffer.deleteCharAt(i7);
        if (i3 != 0)
          localStringBuffer.append('E').append(i3);
        if (paramDouble < 0.0D)
          localStringBuffer.insert(0, '-');
        return localStringBuffer.toString();
        label558: i3 = i2;
      }
      i2 = n;
      i11 = i1;
      break;
      label576: i2 = n;
    }
  }

  public static String doubleToString(double paramDouble, int paramInt)
  {
    return sizeTruncate(doubleToString(paramDouble), paramInt);
  }

  private void insertComma(String paramString, int paramInt1, int paramInt2)
  {
    insertComma(new StringBuilder(paramString), paramInt1, paramInt2);
  }

  private void insertComma(StringBuilder paramStringBuilder, int paramInt1, int paramInt2)
  {
    StringBuilder localStringBuilder1 = getTextBuilder();
    StringBuilder localStringBuilder2 = new StringBuilder();
    int i = localStringBuilder1.length();
    int j = paramStringBuilder.length();
    int k = 0;
    int m = 0;
    int n;
    if (paramInt1 - j >= 0)
      n = paramInt1 - j;
    for (int i1 = n - 1; ; i1--)
    {
      if (i1 < 0)
        break label108;
      char c4 = localStringBuilder1.charAt(i1);
      if ((Cmyfunc.isOnlyDigit(c4)) || (c4 == '.'))
        continue;
      k = i1 + 1;
      if (n != k)
        break label108;
      return;
      n = 0;
      break;
    }
    label108: StringBuilder localStringBuilder3;
    int i3;
    int i4;
    int i5;
    label223: label254: for (int i2 = paramInt2; ; i2++)
    {
      if (i2 <= i)
        if (i2 != i)
          break label223;
      for (m = i; ; m = i2)
      {
        localStringBuilder3 = removeSub(localStringBuilder1, k, m);
        i3 = 0;
        i4 = 0;
        i5 = 0;
        if (i5 <= localStringBuilder3.length())
        {
          if (i5 != localStringBuilder3.length())
            break label260;
          localStringBuilder2.append(changeNumFomat(localStringBuilder3.substring(i3, i5)));
        }
        if (localStringBuilder2.length() == 0)
          break;
        this.mDisplay.getText().replace(k, m, changeColor(localStringBuilder2));
        break;
        char c3 = localStringBuilder1.charAt(i2);
        if ((Cmyfunc.isOnlyDigit(c3)) || (c3 != '.'))
          break label254;
      }
    }
    label260: char c1 = localStringBuilder3.charAt(i5);
    char c2;
    if (i5 < localStringBuilder3.length() - 1)
    {
      c2 = localStringBuilder3.charAt(i5 + 1);
      label292: if ((Cmyfunc.isOnlyDigit(c1)) || (c1 == '.'))
        break label410;
      if ((c1 != 'E') || ((c2 != '-') && (!Cmyfunc.isOnlyDigit(c2)) && (c2 != '+')))
        break label348;
    }
    while (true)
    {
      i5++;
      break;
      c2 = '\000';
      break label292;
      label348: if ((i4 == 69) && ((c1 == '-') || (Cmyfunc.isOnlyDigit(c1)) || (c1 == '+')))
        continue;
      localStringBuilder2.append(changeNumFomat(localStringBuilder3.substring(i3, i5)));
      localStringBuilder2.append(c1);
      i3 = i5 + 1;
      label410: i4 = c1;
    }
  }

  private void reCalculation()
  {
    String str1 = getText();
    int i = str1.indexOf("=");
    StringBuilder localStringBuilder = new StringBuilder(str1.substring(0, i));
    if (str1.length() < i + 1)
    {
      Log.v("Calculator : reCalculaton", "java.lang.StringIndexOutOfBoundsException" + str1.length() + " : " + i);
      clearResult();
    }
    while (true)
    {
      return;
      String str2 = str1.substring(i + 1).replaceAll(",", "");
      Object localObject = "";
      int k;
      int m;
      int n;
      int i1;
      char c;
      try
      {
        localObject = evaluate(localStringBuilder, true);
        localObject = doubleToString(Double.parseDouble((String)localObject), 15);
        int i5 = ((String)localObject).length() - 1;
        if (((String)localObject).charAt(i5) == '.')
        {
          int i6 = ((String)localObject).length() - 1;
          String str5 = ((String)localObject).substring(0, i6);
          localObject = str5;
        }
        if (!str2.equals(localObject))
          clearResult();
      }
      catch (SyntaxException localSyntaxException)
      {
        while (true)
        {
          this.mIsError = true;
          this.mEnterEnd = false;
          this.errorCursor = (1 + localSyntaxException.position);
        }
        j = 0;
        k = 0;
        m = str1.length();
        n = 0;
        i1 = 0;
        int i2 = str1.length();
        if (i1 < i2)
        {
          c = str1.charAt(i1);
          if ((c != '\n') && (c != '='))
            break label298;
          m = i1;
        }
        if ((n <= 1) && (k != 0))
        {
          int i3 = str1.length();
          if (k < i3)
            break label356;
        }
        clearResult();
      }
      continue;
      label298: if (((i1 == 0) || (j == 40)) && ((c == '-') || (c == '+')));
      for (int j = c; ; j = c)
      {
        i1++;
        break;
        if (!Cmyfunc.isOprator(c))
          continue;
        k = i1;
        n++;
      }
      label356: String str3 = str1.substring(k, m);
      String str4;
      for (int i4 = str3.length() - 1; ; i4--)
      {
        if ((i4 < 0) || (str3.charAt(i4) != ')'))
        {
          str4 = str1.substring(k, m);
          if (str4.length() != 0)
            break label426;
          clearResult();
          break;
        }
        m--;
      }
      label426: replaceInput();
      this.mDisplay.getText().append(changeColor(str4));
    }
  }

  public static String sizeTruncate(String paramString, int paramInt)
  {
    String str2;
    if (paramInt == 100)
    {
      str2 = paramString;
      return str2;
    }
    for (int i = 0; i < paramString.length(); i++)
    {
      if ((paramString.charAt(i) != '.') && (paramString.charAt(i) != '-'))
        continue;
      paramInt++;
    }
    int j = paramString.lastIndexOf('E');
    if (j != -1);
    for (String str1 = paramString.substring(j); ; str1 = "")
    {
      int k = str1.length();
      int m = paramInt - k;
      str2 = paramString.substring(0, Math.min(paramString.length() - k, m)) + str1;
      break;
    }
  }

  public void CheckInput()
  {
    int i = 0;
    String str = getText();
    StringBuilder localStringBuilder = getTextBuilder();
    CExpression localCExpression = new CExpression();
    checkError();
    this.mPaste = false;
    if (str.trim().length() == 0);
    while (true)
    {
      return;
      if (((localStringBuilder.length() == 1) && ((localStringBuilder.charAt(0) == '-') || (localStringBuilder.charAt(0) == '('))) || ((localStringBuilder.length() == 2) && (localStringBuilder.equals("√("))) || ((localStringBuilder.length() == 3) && ((localStringBuilder.equals("e^(")) || (localStringBuilder.equals("ln(")))) || ((localStringBuilder.length() == 4) && ((localStringBuilder.equals("sin(")) || (localStringBuilder.equals("cos(")) || (localStringBuilder.equals("tan(")))))
        continue;
      try
      {
        localCExpression.checkInputExp(localStringBuilder, false);
        if (this.errorCursor < 0)
          this.errorCursor = getText().length();
        if (("".equals("***") == true) || (("".length() == 0) && (2131034133 == i)))
          this.mIsError = false;
        if (this.mIsError == true)
          setResult(localStringBuilder, "", i);
        this.mIsError = false;
        this.mEnterEnd = false;
      }
      catch (SyntaxException localSyntaxException)
      {
        while (true)
        {
          this.mIsError = true;
          this.mEnterEnd = false;
          i = localSyntaxException.message;
          this.errorCursor = (1 + localSyntaxException.position);
        }
      }
    }
  }

  public SpannableStringBuilder changeColor(String paramString)
  {
    return changeColor(new StringBuilder(paramString));
  }

  public SpannableStringBuilder changeColor(StringBuilder paramStringBuilder)
  {
    SpannableStringBuilder localSpannableStringBuilder1 = new SpannableStringBuilder(paramStringBuilder);
    int i = 999999999;
    int j = 0;
    if (paramStringBuilder.length() == 0);
    for (SpannableStringBuilder localSpannableStringBuilder2 = localSpannableStringBuilder1.append(""); ; localSpannableStringBuilder2 = localSpannableStringBuilder1)
    {
      return localSpannableStringBuilder2;
      localSpannableStringBuilder1.setSpan(new ForegroundColorSpan(-13312), j, j + 1, 33);
      i = j;
      j++;
      if (j >= paramStringBuilder.length())
        continue;
      char c = paramStringBuilder.charAt(j);
      if ((!Cmyfunc.isOnlyDigit(c)) || (c == ','))
        localSpannableStringBuilder1.setSpan(this.mType, j, j + 1, 33);
      switch (c)
      {
      case '=':
      default:
        if ((j > i) && (Character.isLetter(c)))
          localSpannableStringBuilder1.setSpan(new ScaleXSpan(0.85F), j, j + 1, 33);
        if ((!Cmyfunc.isOpByTwo(c)) || (c == '^'))
          break label269;
        if ((c != '-') || (j <= i))
          break;
      case '\n':
      }
      for (int m = -13312; ; m = -8274177)
      {
        localSpannableStringBuilder1.setSpan(new ForegroundColorSpan(m), j, j + 1, 33);
        break;
        i = 999999999;
        localSpannableStringBuilder1.setSpan(new ForegroundColorSpan(-1), j, j + 1, 33);
        break;
      }
      label269: if (i > j);
      for (int k = -1; ; k = -13312)
      {
        localSpannableStringBuilder1.setSpan(new ForegroundColorSpan(k), j, j + 1, 33);
        break;
      }
    }
  }

  public String changeNumFomat(String paramString)
  {
    Object localObject;
    if (paramString.length() == 0)
      localObject = "";
    while (true)
    {
      return localObject;
      String str1 = paramString.replaceAll(",", "");
      if (str1.contains("NaN"))
      {
        localObject = this.mContext.getResources().getString(2131034113);
        continue;
      }
      if (str1.length() == 0)
      {
        localObject = "";
        continue;
      }
      StringBuilder localStringBuilder = new StringBuilder();
      int i = 0;
      if (str1.contains("E"))
      {
        localObject = str1;
        continue;
      }
      int j = 0;
      label96: if (j <= str1.length())
      {
        if ((j == str1.length()) || ((str1.charAt(j) != '-') && (!Cmyfunc.isOnlyDigit(str1.charAt(j)))))
          i = j;
      }
      else
        if (str1.charAt(0) != '-')
          break label228;
      String str2;
      label228: for (int k = 1; ; k = 0)
      {
        if (str1.charAt(0) == '-')
          localStringBuilder.append("-");
        str2 = str1.substring(k, i);
        if ((!str2.contains("Infinity")) && (!str2.contains("NaN")))
          break label234;
        localObject = this.mContext.getResources().getString(2131034113);
        break;
        j++;
        break label96;
      }
      label234: NumberFormat localNumberFormat = NumberFormat.getNumberInstance(Locale.US);
      try
      {
        localNumberFormat.format(BigDecimal.valueOf(Long.valueOf(str2).longValue()));
        localStringBuilder.append(localNumberFormat.format(BigDecimal.valueOf(Long.valueOf(str2).longValue())));
        localStringBuilder.append(str1.substring(i));
        localObject = localStringBuilder.toString();
      }
      catch (Exception localException)
      {
        localObject = this.mContext.getResources().getString(2131034113);
      }
    }
  }

  public int checkError()
  {
    int i = 0;
    int k;
    if (!this.mPaste)
    {
      int m = checkCharCount(getTextBuilder(), "=");
      if (m == 0)
      {
        k = -1;
        return k;
      }
      if (m > 1)
        i = getText().lastIndexOf("=");
      if ((i > 0) && (getText().charAt(i - 1) == '\n'))
        i--;
      int n = getText().substring(0, i).lastIndexOf("\n");
      if ((n != -1) && (n + 1 <= getTextLength()))
        this.mDisplay.getText().delete(0, n + 1);
    }
    int j = getText().indexOf("=");
    switch (j)
    {
    default:
      c = '\000';
      if (j >= getTextLength())
        break;
      if (getTextLength() != j + 1);
    case -1:
    }
    for (char c = '\000'; ; c = getText().charAt(j + 1))
    {
      if (((!Cmyfunc.isOnlyDigit(c)) && (c != '-')) || (c == 0))
      {
        clearResult();
        j = -1;
      }
      k = j;
      break;
    }
  }

  public void clearResult()
  {
    StringBuilder localStringBuilder = getTextBuilder();
    int i = localStringBuilder.length();
    int j = getText().indexOf("=");
    if (j == -1);
    while (true)
    {
      return;
      if ((j > 0) && (localStringBuilder.charAt(j - 1) == '\n'))
        j--;
      this.mDisplay.getText().delete(j, i);
      setFrontText(this.mDisplay.getText().toString());
    }
  }

  public int commaCount(StringBuilder paramStringBuilder)
  {
    return checkCharCount(paramStringBuilder, ",");
  }

  public String evaluate(StringBuilder paramStringBuilder, boolean paramBoolean)
    throws SyntaxException
  {
    CExpression localCExpression = new CExpression();
    if (!localCExpression.checkInputExp(paramStringBuilder, paramBoolean))
      throw this.exception.set(2131034113, getTextLength());
    try
    {
      String str3 = localCExpression.evaluateExp();
      return str3;
    }
    catch (SyntaxException localSyntaxException2)
    {
      this.mIsError = true;
      if (paramStringBuilder.indexOf("÷0") != -1);
      int m;
      for (int k = 1 + paramStringBuilder.indexOf("÷0"); ; k = paramStringBuilder.length() - 1)
      {
        this.errorCursor = k;
        String str2 = localSyntaxException2.getMessage();
        m = localSyntaxException2.message;
        if (str2 == null)
          str2 = "null";
        if (!str2.contains("Division by zero"))
          break;
        throw this.exception.set(2131034117, this.errorCursor);
      }
      if ((m == 2131034118) || (m == 2131034119))
        throw this.exception.set(m, this.errorCursor);
      throw this.exception.set(2131034113, this.errorCursor);
    }
    catch (Exception localException)
    {
      this.mIsError = true;
      if (paramStringBuilder.indexOf("÷0") == -1)
        break label270;
    }
    int i = 1 + paramStringBuilder.indexOf("÷0");
    this.errorCursor = i;
    String str1 = localException.getMessage();
    if (str1 == null)
      str1 = "null";
    SyntaxException localSyntaxException1 = this.exception;
    if (str1.contains("Division by zero"));
    for (int j = 2131034117; ; j = 2131034113)
    {
      throw localSyntaxException1.set(j, this.errorCursor);
      label270: i = paramStringBuilder.length() - 1;
      break;
    }
  }

  public int getCursor(EditText paramEditText, boolean paramBoolean)
  {
    int i = paramEditText.getSelectionStart();
    int j = paramEditText.getSelectionEnd();
    if (paramBoolean);
    for (int k = Math.min(i, j); ; k = Math.max(i, j))
      return k;
  }

  public String getFrontText()
  {
    return this.frontText;
  }

  public String getText()
  {
    return this.mDisplay.getText().toString();
  }

  public StringBuilder getTextBuilder()
  {
    clearSB();
    return this.sb.append(this.mDisplay.getText());
  }

  public int getTextLength()
  {
    return this.mDisplay.getText().length();
  }

  public boolean getmCursorState()
  {
    return this.mCursorState;
  }

  public void goneCursor()
  {
    this.mDisplay.setCursorVisible(false);
    this.mHistoryScreen.setCursorVisible(false);
    setmCursorState(false);
  }

  public void insert(StringBuilder paramStringBuilder)
  {
    int i = 0;
    int j = 0;
    int k = paramStringBuilder.charAt(0);
    this.mIsError = false;
    int m = getCursor(this.mDisplay, true);
    int n = getCursor(this.mDisplay, false);
    Editable localEditable;
    int i1;
    if ((isSelecting()) && (n == getTextLength()) && (m != n))
    {
      this.mDisplay.getText().delete(m, n);
      if ((paramStringBuilder.length() == 1) && (Cmyfunc.isOnlyDigit(paramStringBuilder.charAt(0))))
        onEnterEnd();
      replaceInput();
      localEditable = this.mDisplay.getText();
      i1 = getCursor(this.mDisplay, false);
      if (((localEditable.length() != 0) && (i1 != 0)) || ((!paramStringBuilder.toString().equals("%")) && (!paramStringBuilder.toString().equals("!")) && (!paramStringBuilder.toString().equals("^(2)")) && (!paramStringBuilder.toString().equals("^("))))
        break label214;
    }
    label214: label249: 
    do
      while (true)
      {
        return;
        this.mDisplay.setSelection(this.mDisplay.getText().length());
        break;
        if (originCount(getTextBuilder()) + originCount(paramStringBuilder) <= 100)
          break label249;
        setResult(getTextBuilder(), "", 2131034120);
      }
    while ((Cmyfunc.isOprator(k)) && (i1 == 0) && (k != 45));
    if (i1 > 0)
      i = localEditable.charAt(i1 - 1);
    int i7;
    label321: SpannableStringBuilder localSpannableStringBuilder7;
    if ((Cmyfunc.isOprator(i)) && (Cmyfunc.isOprator(k)))
      if (Cmyfunc.isOprator(i))
      {
        if (0 != 0)
          i1++;
        i7 = i1 - 1;
        if (i7 > 0)
        {
          if (Cmyfunc.isOprator(this.mDisplay.getText().charAt(i7 - 1)))
            break label467;
          j = i7;
        }
        int i8 = 0;
        if ((j > 0) && (this.mDisplay.getText().charAt(j - 1) == '('))
          i8 = 1;
        if (((i8 == 0) || (k == 45) || (k == 43)) && ((j != 0) || (k == 45)))
          break label473;
        localSpannableStringBuilder7 = changeColor("");
        label419: localEditable.replace(j, i1, localSpannableStringBuilder7);
      }
    while (true)
    {
      label432: CheckInput();
      int i2 = getCursor(this.mDisplay, false);
      insertComma(paramStringBuilder, i2, i2);
      this.mDisplay.getSelectionEnd();
      break;
      label467: i7--;
      break label321;
      label473: localSpannableStringBuilder7 = changeColor(paramStringBuilder);
      break label419;
      if ((i == 48) && (Cmyfunc.isOnlyDigit(k)))
      {
        int i3 = 0;
        label585: label613: for (int i4 = i1 - 1; ; i4--)
        {
          int i6;
          if (i4 >= 0)
          {
            i6 = localEditable.charAt(i4);
            if ((Cmyfunc.isOnlyDigit(i6)) || (i6 == 46) || (i6 != 960))
              break label585;
          }
          while (true)
          {
            if (i3 != 0)
              break label619;
            if (k == 0)
              break;
            int i5 = i1 - 1;
            SpannableStringBuilder localSpannableStringBuilder6 = changeColor(paramStringBuilder);
            localEditable.replace(i5, i1, localSpannableStringBuilder6);
            break label432;
            if ((i6 != 46) && ((!Cmyfunc.isOnlyDigit(i6)) || (i6 == 48)))
              break label613;
            i3 = 1;
          }
        }
        label619: SpannableStringBuilder localSpannableStringBuilder5 = changeColor(paramStringBuilder);
        localEditable.insert(i1, localSpannableStringBuilder5);
        continue;
      }
      if (((i == 41) || (i == 101) || (i == 33) || (i == 37) || (i == 960)) && (Cmyfunc.isOnlyDigit(k)))
      {
        SpannableStringBuilder localSpannableStringBuilder4 = changeColor("×" + paramStringBuilder);
        localEditable.insert(i1, localSpannableStringBuilder4);
        continue;
      }
      if ((i == 41) || (Cmyfunc.isOnlyDigit(i)))
      {
        if ((k == 115) || (k == 99) || (k == 116) || (k == 108) || (k == 8730) || (k == 101) || (k == 960));
        for (SpannableStringBuilder localSpannableStringBuilder1 = changeColor("×" + paramStringBuilder); ; localSpannableStringBuilder1 = changeColor(paramStringBuilder))
        {
          localEditable.insert(i1, localSpannableStringBuilder1);
          break;
        }
      }
      if ((i == 101) || (i == 33) || (i == 37) || (i == 960))
      {
        if (((k != 115) && (k != 99) && (k != 116) && (k != 108) && (k != 8730) && (k != 101) && (k != 960)) || ((i != k) || (((k == 101) || (k == 960)) && (i == k))));
        for (SpannableStringBuilder localSpannableStringBuilder2 = changeColor("×" + paramStringBuilder); ; localSpannableStringBuilder2 = changeColor(paramStringBuilder))
        {
          localEditable.insert(i1, localSpannableStringBuilder2);
          break;
        }
      }
      if ((i == 40) && ((k == 215) || (k == 247)))
        break;
      SpannableStringBuilder localSpannableStringBuilder3 = changeColor(paramStringBuilder);
      localEditable.insert(i1, localSpannableStringBuilder3);
    }
  }

  public boolean isCheckResult()
  {
    int i = getTextBuilder().indexOf("=");
    int j;
    if ((i == -1) || (this.mDisplay.getText().length() - 1 == i))
      j = 0;
    while (true)
    {
      return j;
      char c = this.mDisplay.getText().charAt(i + 1);
      if ((Cmyfunc.isOnlyDigit(c)) || (c == '-'))
      {
        j = 1;
        continue;
      }
      j = 0;
    }
  }

  public boolean isDisplayScreen()
  {
    if (this.mDisplay.getText().length() > 0);
    for (int i = 1; ; i = 0)
      return i;
  }

  public boolean isHistoryScreen()
  {
    if ((this.mHistoryScreen.getText().length() > 0) || (this.mHistory.isHistory()));
    for (int i = 1; ; i = 0)
      return i;
  }

  public boolean isLongClick()
  {
    return this.isLongClick;
  }

  public boolean isMultiSelection(EditText paramEditText)
  {
    EditText localEditText;
    if (paramEditText.getId() == 2130968580)
    {
      localEditText = this.mHistoryScreen;
      if (getCursor(localEditText, true) == getCursor(localEditText, false))
        break label42;
    }
    label42: for (int i = 1; ; i = 0)
    {
      return i;
      localEditText = this.mDisplay;
      break;
    }
  }

  public boolean isSelecting()
  {
    return this.isSelecting;
  }

  public void onAbs()
  {
    replaceInput();
    StringBuilder localStringBuilder1 = getTextBuilder();
    int i = getTextLength();
    StringBuilder localStringBuilder2 = new StringBuilder();
    if ((i > 0) && ((localStringBuilder1.charAt(i - 1) == ')') || (localStringBuilder1.charAt(i - 1) == 'e') || (localStringBuilder1.charAt(i - 1) == '!') || (localStringBuilder1.charAt(i - 1) == '%') || (localStringBuilder1.charAt(i - 1) == 'π') || (Cmyfunc.isOnlyDigit(localStringBuilder1.charAt(i - 1)))))
      localStringBuilder2.append("×");
    localStringBuilder2.append("abs(");
    this.mDisplay.getText().insert(i, changeColor(localStringBuilder2));
    int j = getTextLength();
    insertComma(localStringBuilder2, j, j);
    CheckInput();
  }

  public void onBackspace()
  {
    if (this.mEnterEnd)
      this.mEnterEnd = false;
    replaceInput();
    onClearOrigin();
    String str1 = getText();
    String str2 = "";
    int i = getTextLength();
    int j = -1;
    int k = 0;
    if (k < this.checkChar.length)
    {
      j = str1.lastIndexOf(this.checkChar[k]);
      if (j == -1);
      do
      {
        k++;
        break;
      }
      while (j + this.checkChar[k].length() != i);
      Log.e("onBackspace", "check[i] : " + this.checkChar[k]);
      str2 = this.checkChar[k];
    }
    this.mDisplay.getSelectionStart();
    if (!str2.equals(""))
      this.mDisplay.getText().delete(j, i);
    while (true)
    {
      int m = this.mDisplay.getSelectionStart();
      insertComma("", m, m);
      return;
      this.mDisplay.dispatchKeyEvent(new KeyEvent(0, 67));
    }
  }

  public void onClear()
  {
    this.mDisplay.setText("");
    this.mIsError = false;
    this.mEnterEnd = false;
    Cmyfunc.clearmOrigin();
  }

  public void onClearOrigin()
  {
    int i = Cmyfunc.getmOrigin().length();
    if (i == 0);
    while (true)
    {
      return;
      int j = getText().indexOf(Cmyfunc.getmOrigin());
      if (j == -1)
        continue;
      if (i + j < getTextLength())
      {
        char c = getText().charAt(i + j);
        if ((Cmyfunc.isOpByTwo(c)) || (c == '!'))
          continue;
      }
      Cmyfunc.clearmOrigin();
    }
  }

  public void onDecimal()
  {
    int i = 0;
    if (this.mEnterEnd)
      onClear();
    replaceInput();
    StringBuilder localStringBuilder1 = getTextBuilder();
    StringBuilder localStringBuilder2 = new StringBuilder();
    int j = getTextLength();
    if ((j > 0) && (Cmyfunc.isChar(localStringBuilder1.charAt(j - 1))));
    while (true)
    {
      return;
      if (j == 0)
      {
        this.mDisplay.getText().insert(j, changeColor("0."));
        insertComma("0.", 0, 0);
        continue;
      }
      int k = localStringBuilder1.charAt(j - 1);
      for (int m = 0; ; m++)
      {
        if (m >= j)
          break label164;
        if ((localStringBuilder1.charAt(m) == '.') && (i == 1))
          break;
        if (Cmyfunc.isToken(localStringBuilder1.charAt(m)))
          i = 0;
        if (localStringBuilder1.charAt(m) != '.')
          continue;
        i = 1;
      }
      label164: if (i != 0)
        break;
      if ((k == 41) || (k == 33) || (k == 101) || (k == 960))
      {
        localStringBuilder2.append("×0.");
        this.mDisplay.getText().insert(j, changeColor(localStringBuilder2));
        continue;
      }
      if (!Cmyfunc.isOnlyDigit(k))
        break label288;
    }
    label288: for (String str = "."; ; str = "0.")
    {
      localStringBuilder2.append(str);
      this.mDisplay.getText().insert(j, changeColor(localStringBuilder2));
      CheckInput();
      insertComma(localStringBuilder2, getTextLength(), getTextLength());
      break;
    }
  }

  public void onEnter()
  {
    onEnter(true);
  }

  public void onEnter(boolean paramBoolean)
  {
    String str1 = getText();
    onClearOrigin();
    if (str1.trim().length() == 0);
    while (true)
    {
      return;
      Object localObject;
      String str2;
      int i;
      StringBuilder localStringBuilder;
      if (this.mEnterEnd)
      {
        reCalculation();
        repairDisplay();
        localObject = "";
        str2 = "";
        i = 0;
        localStringBuilder = getTextBuilder();
      }
      try
      {
        str2 = evaluate(localStringBuilder, true);
        localObject = doubleToString(Double.parseDouble(str2), 15);
        if (((String)localObject).charAt(((String)localObject).length() - 1) == '.')
        {
          String str4 = ((String)localObject).substring(0, ((String)localObject).length() - 1);
          localObject = str4;
        }
        setResult(localStringBuilder, (String)localObject, i);
        if ((!this.mIsError) && (!((String)localObject).contains("Infinity")) && (!((String)localObject).contains("NaN")))
        {
          String str3 = changeNumFomat((String)localObject);
          if (paramBoolean == true)
            this.mHistory.enter(localStringBuilder.toString(), str3);
          Cmyfunc.setmTrans(str2);
          Cmyfunc.setmOrigin(str3);
          this.mEnterEnd = true;
        }
        this.mIsError = false;
        continue;
        clearResult();
      }
      catch (SyntaxException localSyntaxException)
      {
        while (true)
        {
          this.mIsError = true;
          this.mEnterEnd = false;
          i = localSyntaxException.message;
          this.errorCursor = (1 + localSyntaxException.position);
        }
      }
      catch (Exception localException)
      {
        while (true)
        {
          this.mIsError = true;
          this.mEnterEnd = false;
          i = 2131034117;
          localException.printStackTrace();
        }
      }
    }
  }

  public void onEnterEnd()
  {
    if (this.mEnterEnd)
      onClear();
  }

  public void onFraction()
  {
    replaceInput();
    int i = getTextLength();
    String str = getText();
    StringBuilder localStringBuilder = new StringBuilder();
    if (i == 0)
    {
      localStringBuilder.append("1÷");
      this.mDisplay.getText().insert(i, changeColor(localStringBuilder));
      insertComma(localStringBuilder, getTextLength(), getTextLength());
    }
    while (true)
    {
      return;
      if ((Cmyfunc.isOnlyDigit(str.charAt(i - 1))) || (str.charAt(i - 1) == ')') || (str.charAt(i - 1) == 'e') || (str.charAt(i - 1) == '!') || (str.charAt(i - 1) == 'π'))
        localStringBuilder.append("×");
      localStringBuilder.append("(1÷");
      this.mDisplay.getText().insert(i, changeColor(localStringBuilder));
      insertComma(localStringBuilder, getTextLength(), getTextLength());
    }
  }

  public void onHisClear()
  {
    this.mHistory.clear();
    this.mHistoryScreen.setText("");
    onClear();
  }

  public void onParenthesis()
  {
    int i = 0;
    replaceInput();
    String str1 = getText();
    int j = getTextLength();
    for (int k = 0; k < j; k++)
    {
      if (str1.charAt(k) == '(')
        i++;
      if (str1.charAt(k) != ')')
        continue;
      i--;
    }
    StringBuilder localStringBuilder = new StringBuilder();
    int m = 0;
    if (j > 0)
      m = str1.charAt(j - 1);
    if (i > 0)
    {
      if ((Cmyfunc.isOnlyDigit(m)) || (m == 33) || (m == 37) || (m == 41) || (m == 101) || (m == 960) || (m == 46))
      {
        localStringBuilder.append(")");
        this.mDisplay.getText().insert(j, changeColor(localStringBuilder));
        CheckInput();
        insertComma(localStringBuilder, getTextLength(), getTextLength());
        return;
      }
      if ((m == 41) && (j > 0));
      for (String str3 = "×("; ; str3 = "(")
      {
        localStringBuilder.append(str3);
        break;
      }
    }
    if (((Character.isDigit(m)) || (m == 101) || (m == 33) || (m == 37) || (m == 960) || (m == 44) || (m == 46) || (m == 41)) && (j > 0));
    for (String str2 = "×("; ; str2 = "(")
    {
      localStringBuilder.append(str2);
      break;
    }
  }

  public void onPlusMinus()
  {
    replaceInput();
    String str = getText();
    int i = getTextLength();
    int j = 0;
    int k = 0;
    if (i == 0)
      this.mDisplay.getText().insert(0, changeColor("-"));
    while (true)
    {
      return;
      int m = i;
      label48: int n;
      if (m > 0)
      {
        if (Cmyfunc.isToken(str.charAt(m - 1)))
          j = m - 1;
      }
      else
      {
        if (str.charAt(j) != '-')
          break label237;
        n = j;
        if ((j != 0) || (i != 1))
          break label187;
        k = 3;
      }
      while (true)
        switch (k)
        {
        default:
          break;
        case 1:
          this.mDisplay.getText().insert(0, changeColor("-"));
          break;
          if ((m == 1) && (!Cmyfunc.isToken(str.charAt(m - 1))))
            j = 0;
          m--;
          break label48;
          label187: if ((j > 0) && (str.charAt(j - 1) == '('))
          {
            k = 3;
            continue;
          }
          if (j == 0)
          {
            k = 3;
            continue;
          }
          if (str.charAt(j - 1) == '(')
            continue;
          k = 4;
          continue;
          label237: n = j;
          if ((j == 0) && (str.charAt(j) != '('))
          {
            k = 1;
            continue;
          }
          if (str.charAt(j) == '(')
          {
            k = 2;
            continue;
          }
          if (str.charAt(j) == ')')
          {
            k = 5;
            continue;
          }
          k = 4;
        case 2:
        case 3:
        case 4:
        case 5:
        }
      this.mDisplay.getText().insert(n + 1, changeColor("-"));
      continue;
      this.mDisplay.getText().replace(n, n + 1, "");
      continue;
      this.mDisplay.getText().insert(n + 1, changeColor("(-"));
      continue;
      this.mDisplay.getText().insert(n + 1, changeColor("×(-"));
    }
  }

  public void onShift(View paramView, boolean paramBoolean)
  {
    if (paramBoolean == this.isSelecting)
      return;
    if (paramBoolean)
      paramView.dispatchKeyEvent(new KeyEvent(0, 59));
    while (true)
    {
      setSelecting(paramBoolean);
      break;
      paramView.dispatchKeyEvent(new KeyEvent(1, 59));
      paramView.setSelected(false);
    }
  }

  public int originCount(StringBuilder paramStringBuilder)
  {
    if (paramStringBuilder.toString().length() == 0);
    for (int i = 0; ; i = paramStringBuilder.toString().length() - commaCount(paramStringBuilder))
      return i;
  }

  public StringBuilder removeSub(StringBuilder paramStringBuilder, int paramInt1, int paramInt2)
  {
    if (paramStringBuilder.length() == 0);
    StringBuilder localStringBuilder;
    for (Object localObject = paramStringBuilder; ; localObject = localStringBuilder)
    {
      return localObject;
      localStringBuilder = new StringBuilder();
      for (int i = paramInt1; i < paramInt2; i++)
      {
        if (paramStringBuilder.charAt(i) == ',')
          continue;
        localStringBuilder.append(paramStringBuilder.charAt(i));
      }
    }
  }

  public void repairDisplay()
  {
    int i = 0;
    StringBuilder localStringBuilder = getTextBuilder();
    for (int j = localStringBuilder.length() - 1; j >= 0; j--)
    {
      if (localStringBuilder.charAt(j) == ')')
        i--;
      if (localStringBuilder.charAt(j) != '(')
        continue;
      i++;
    }
    if (i == 0);
    while (true)
    {
      return;
      for (int k = 0; k < i; k++)
        this.mDisplay.getText().append(")");
    }
  }

  public void replaceInput()
  {
    this.mEnterEnd = false;
    int i = checkError();
    int j = getCursor(this.mDisplay, true);
    int k = getCursor(this.mDisplay, false);
    StringBuilder localStringBuilder = new StringBuilder();
    label110: int m;
    if (i != -1)
    {
      localStringBuilder.append(getTextBuilder().substring(i + 1).replace("\n", ""));
      this.mDisplay.setText(changeColor(localStringBuilder));
      if (j - i - 1 > 0)
      {
        j = j - i - 1;
        if (k - i - 1 <= 0)
          break label160;
        k = k - i - 1;
      }
    }
    else
    {
      m = getTextLength();
      if (j > m)
        j = m;
      if (k > m)
        k = m;
      if ((j == k) || (k != m))
        break label165;
      this.mDisplay.setSelection(j, k);
    }
    while (true)
    {
      return;
      j = 0;
      break;
      label160: k = 0;
      break label110;
      label165: this.mDisplay.setSelection(m);
    }
  }

  public void setFrontText(String paramString)
  {
    this.frontText = paramString;
  }

  public void setLongClick(boolean paramBoolean)
  {
    this.isLongClick = paramBoolean;
  }

  public void setResult(StringBuilder paramStringBuilder, String paramString, int paramInt)
  {
    String str;
    if (paramInt != 0)
    {
      str = this.mContext.getResources().getString(paramInt);
      paramStringBuilder.length();
      switch (paramInt)
      {
      default:
        if (((paramInt != 0) || (str.contains("Infinity")) || (str.contains("NaN"))) && ((str.contains("Infinity")) || (str.contains("NaN"))))
        {
          paramInt = 2131034113;
          str = this.mContext.getResources().getString(paramInt);
          this.errorCursor = this.mDisplay.getText().length();
        }
        if (paramInt == 0)
          break;
      case 2131034114:
      case 2131034115:
      case 2131034116:
      case 2131034134:
      }
    }
    while (true)
    {
      int i = this.mDisplay.getText().length();
      this.mDisplay.getText().insert(i, changeColor("\n=" + str));
      setFrontText("");
      this.mDisplay.setSelection(this.mDisplay.getText().length());
      while (true)
      {
        return;
        str = paramString;
        break;
        this.mDisplay.setText(changeColor(getFrontText()));
        setFrontText("");
        continue;
        this.mDisplay.dispatchKeyEvent(new KeyEvent(0, 67));
        setFrontText("");
      }
      str = changeNumFomat(str);
    }
  }

  public void setSelecting(boolean paramBoolean)
  {
    this.isSelecting = paramBoolean;
  }

  public void setmCursorState(boolean paramBoolean)
  {
    this.mCursorState = paramBoolean;
  }

  public void showCursor()
  {
    this.mDisplay.setCursorVisible(true);
    this.mHistoryScreen.setCursorVisible(true);
    setmCursorState(true);
  }
}

/* Location:           C:\Development\Android_Java_C\Workspace\TouchWizCalculator\TouchWizCalculator_dex2jar.jar
 * Qualified Name:     com.sec.android.app.calculator.EventHandler
 * JD-Core Version:    0.6.0
 */